﻿using DesktopToy.Core;

namespace DesktopToy.Test;

/// <summary>
/// 测试获取天气，此处使用高德API
/// </summary>
public class TestWeather
{
    /// <summary>
    /// 高德Web服务的Key，此处使用的Key是作者本人测试使用的，随时可能失效，推荐大家去申请一个：https://lbs.amap.com/api/webservice/guide/api/weatherinfo
    /// </summary>
    private const string WEB_SERVICE_API_KEY = "3fce616e8d8a7187d5f6af665a4ff61f";
    
    /// <summary>
    /// 天气预报的adcode，参考项目根目录的 AMap_adcode_citycode.xlsx，或者到官网下载一份：https://lbs.amap.com/api/webservice/download
    /// </summary>
    private const int WEATHER_ADCODE = 450702;

    
    /// <code>
    /// 示例返回结果：
    /// LiveWeather { Province = 广西, City = 钦南区, Weather = 雾, Temperature = 14, WindDirection = 东北, WindPower = ≤3, Humidity = 100, ReportTime = 2025/3/10 0:01:51 }
    /// </code>
    [Test]
    public void TestGetLiveWeather()
    {
        var weather = WebApi.GetLiveWeather(WEB_SERVICE_API_KEY, WEATHER_ADCODE);
        TestContext.WriteLine(weather);
        Assert.That(weather.Province, Is.EqualTo("广西"));
    }
    
    /// <summary>
    /// 示例返回结果：
    /// ForecastWeather { Date = 2025/3/10 0:00:00, Week = 1, DayWeather = 阴, NightWeather = 小雨, DayTemperature = 22, NightTemperature = 14, DayWind = 东南, NightWind = 东南, DayPower = 1-3, NightPower = 1-3 }
    /// </summary>
    [Test]
    public void TestGetForecastWeather()
    {
        var weatherList = WebApi.GetForecastWeather(WEB_SERVICE_API_KEY, WEATHER_ADCODE).ToList();
        foreach (var weather in weatherList)
        {
            TestContext.WriteLine(weather);
        }
        
        Assert.That(weatherList.Count, Is.GreaterThan(0));
    }
}